﻿using System;
using System.Collections.Generic;
using System.Text;

namespace LoginServer.Converter
{
    public class ConvertDataUser
    {
        public object[] GetData(object[] param)
        {
            object[] tmp = new object[param.Length - 1];
            for (int i = 1; i < param.Length; i++)
            {
                tmp[i - 1] = param[i];
            }
            return tmp;
        }
        public User GetUserConnection(object[] param)
        {
            return (User)param[0];
        }
        public void ConvertReceive_L_Login(ref string username,ref string pass,object[] param)
        {
            object[] data = GetData(param);
            byte[] tmp = LConverter.ConvertObjectToByte(data);           
            string[] r = Encoding.UTF8.GetString(tmp, 0, tmp.Length).Split(":".ToCharArray());
            username = r[0];
            pass = r[1];
        }
        public void ConvertReceive_L_JoinTable(ref int TableID,object[] param)
        {
            object[] data = GetData(param);
            byte[] tmp = LConverter.ConvertObjectToByte(data);
            TableID = BitConverter.ToInt32(tmp, 0);
        }
        public void ConvertReceive_L_OutTable(ref int TableID,object[] param)
        {
            object[] data = GetData(param);
            byte[] tmp = LConverter.ConvertObjectToByte(data);
            TableID = BitConverter.ToInt32(tmp, 0);
        }

        //chat
        public string[] ConvertReceive_L_Chat_OK(object[] param)
        {
            string[] list = new string[3];
            object[] data = GetData(param);
            byte[] tmp = LConverter.ConvertObjectToByte(data);
            list = Encoding.UTF8.GetString(tmp, 0, tmp.Length).Split(":".ToCharArray());
            return list;
        }

        public string[] ConvertReceive_L_Chat_Channel(object[] param)
        {
            string[] list = new string[3];
            object[] data = GetData(param);
            byte[] tmp = LConverter.ConvertObjectToByte(data);
            list = Encoding.UTF8.GetString(tmp, 0, tmp.Length).Split(":".ToCharArray());
            return list;
        }
        //list user
        public string ConvertReceive_L_User_AllOn(object[] param)
        {
            string list = "";
            object[] data = GetData(param);
            byte[] tmp = LConverter.ConvertObjectToByte(data);
            list = Encoding.UTF8.GetString(tmp, 0, tmp.Length);
            return list;
        }

        internal void ConvertReceive_L_JoinRoom(ref int RoomID, object[] param)
        {
            object[] data = GetData(param);
            byte[] tmp = LConverter.ConvertObjectToByte(data);
            RoomID = BitConverter.ToInt32(tmp, 0);
        }

        internal void ConvertReceive_L_CreateRoom(ref string RoomName, object[] param)
        {
            object[] data = GetData(param);
            byte[] tmp = LConverter.ConvertObjectToByte(data);
            RoomName = Encoding.UTF8.GetString(tmp);
        }

        internal void ConvertReceive_L_JoinRoomF(ref int UserCreateID, object[] param)
        {
            object[] data = GetData(param);
            byte[] tmp = LConverter.ConvertObjectToByte(data);
            UserCreateID = BitConverter.ToInt32(tmp, 0);
        }

        internal void ConvertReceive_L_OutRoom(ref int RoomID, object[] param)
        {
            object[] data = GetData(param);
            byte[] tmp = LConverter.ConvertObjectToByte(data);
            RoomID = BitConverter.ToInt32(tmp, 0);
        }

        internal void ConvertReceive_L_CreateTable(ref int RoomID, object[] param)
        {
            object[] data = GetData(param);
            byte[] tmp = LConverter.ConvertObjectToByte(data);
            RoomID = BitConverter.ToInt32(tmp, 0);
        }
    }
}
